package BIO;

import java.io.*;
import java.net.Socket;

/**
 * @author fangkun
 * @create 2022-06-01-11:22
 */
public class SocketThread implements Runnable {

    private Socket socket;

    public SocketThread(Socket socket) {
        this.socket=  socket;
    }

    @Override
    public void run() {

        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(socket.getInputStream()));

            String clientStr = bufferedReader.readLine();
            System.out.println("收到客户端发送的消息：" + clientStr);

            BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
            bufferedWriter.write("receive a message:" + clientStr + "\n");
            bufferedWriter.flush();

        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            //TODO 关闭IO流
        }

    }
}
